package com.lottery.utils;

/**
 * 
 * @author zhiping_chen
 * 
 */
public class StringUtil {
	
	public static boolean isAllNum(String src) {
		if (src == null || src.length() == 0) {
			return false;
		}
		for (int i = 0; i < src.length(); i++) {
			char c = src.charAt(i);
			if (c < 0x30 || c > 0x39)// 不再0-9范围
			{
				return false;
			}
		}
		return true;
	}

	/***
	 * 产生指定长度的码,数值左补0
	 * 
	 * @param srcStr
	 * @param length
	 * @param allNum
	 *            true纯数值
	 * @return
	 */
	public static String supplyCode(String srcStr, int length, boolean allNum) {
		String result = srcStr;
		if (srcStr.length() < length) {
			for (int i = 0; i < length - srcStr.length(); i++) {
				if (allNum) {// 纯数值左补0
					result = "0".concat(result);
				} else {// 纯字母右补" "
					result += " ";
				}
			}
		} else if (srcStr.length() > length) {
		}
		return result;
	}

	/*
	 * 汉字字母混合字符串长度，汉字算两个长度，字母算一个长度
	 */
	public static int strLength(String str) {
		int m = 0;
		char arr[] = str.toCharArray();
		for(int i = 0; i < arr.length; i++) {
			char c = arr[i];
			if(c >= 0x4e00 && c <= 0x9fa5) {
				m += 2;
			}
			if(c > 0x00 && c < 0x90) {
				m ++;
			}
		}
		return m;
	}
}
